<?php

/**
 * gpa_new Description
 * @package
 * @name controller_tools
 * @filesource controller_tools.php
 * @author Meta Sanjaya
 */

class controller_tools extends Controller {
    public function  __construct() {
        parent::__construct();
    }

    public function search($param) {
        $get = getInstance('request')->get;
        
        $return = "";

        if(isset($param[0]) && isset($get['q']) && !empty($get['q'])) {
            $data['cat'] = strtolower($param[0]);
            $data['tool'] = $get['q'];

            $model = $this->getModel();
            $array = $model->searchTools($data);

            //var_dump($array);

            foreach($array as $a) {
                $value = $a['tools'];
                $return .= "$value|$value\n";
            }
        }

        die($return);
    }

    public function addTool($param) {
        $post = getInstance('request')->post;

        if(isset($param[0]) && count($post)) {
            $model = $this->getModel();
            $model->addTool($param[0], $post['tool_name']);
        }

        redirect('user/tools');
    }

    public function delTool($param) {
        $tid = intval(@$param[0]);
        $model = $this->getModel();
        $model->delTool($tid);

        redirect('user/tools');
    }
}

?>
